package com.spring.task;

import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Scheduled;

import com.admin.util.ChainUtil;
import com.cxtj.CxBean;
import com.cxtj.CxtjDAO;
import com.cxtj.EtlBean;
import com.cxtj.UserDAO;


public class lksjk {

	  @Resource(name = "CxtjDAO")
	  CxtjDAO cxDao;	
	  @Resource(name = "UserDAO")
	  UserDAO userDAO; 
	  @Resource(name = "ChainorcDao")
	  ChainorcDao coDao;
	
    public void print(){  
        System.out.println(coDao.getCountGwcx());
    }  
    
    public void etlData() throws SQLException{  
    	System.out.println("===============etl开始=============================");
    	System.out.println("正在获取ETL配置表......");	
		List<EtlBean> tbList = userDAO.getEtlRec();
		System.out.println("ETL配置表获取完成，正在根据ETL配置从Oracle或者数据......");					
		List<CxBean> cxList=coDao.getCxListByTableAndUser(tbList);		
		System.out.println("数据获取完成，正在根据ETL配置从Oracle或者数据......");
		if(cxList!=null && cxList.size()>0)
		{
			System.out.println("已获取数据数量："+cxList.size()+"正在向区块链插入数据......");
			ChainUtil cu = new ChainUtil();		
			String res = cu.insertList2Chain(cxList);
			System.out.println("向区块链插入数据："+res);
			List<EtlBean> tbList2=cxDao.getETL(tbList);
			System.out.println("正在更新ETL配置表......");
			for(EtlBean tb:tbList2){
				System.out.println(userDAO.updateETL(tb));
			}
		}
		else{
			System.out.println("无最新数据。");
		}	
		System.out.println("===============本轮etl完成===========================");
    }  
}  

/*
String Str = cxDao.getMaxDate().get("maxDate").toString();	
Timestamp ts = Timestamp.valueOf(Str);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateStr = sdf.format(ts);
System.out.println("当前数据截止时间："+dateStr);
List<CxBean> cxList = chainorcDao.getCxList(dateStr,null);
if(cxList!=null && cxList.size()>0)
{
	System.out.println("获取数据数量："+cxList.size());
	ChainUtil cu = new ChainUtil();		
	String res = cu.insertList2Chain(cxList);
	System.out.println("状态："+res);
}
else{
	System.out.println("无最新数据。");
}*/